jQuery(document).ready(
function($)
{
	years = {};
	$('a.year').each(function() {
		$($(this).attr('title').split(' ')).each(function() { 
			if (this !== '') {
				years[this] = this;
			}    
		});
	});
	
	$.each( years, function(index, item){
		if ($('div.post.'+item).length < 1 ) {
		   $("a[title='"+ item +"']").addClass("dim");
		}
	});
	
	
	$(".year").click(function () { 
	
		$("a").removeClass("current-yr");
		var year = $(this).attr("title");
		$(this).addClass("current-yr");
		
		if ($('div.post.'+year).length ) {
			$("div.post").show();
			$(".year-filter-none, h3.year-filter-hide").hide();
			$(".year-filter-hide").prev("br").hide();
			$(".year-filter-heading").html("Projects in "+year).show();
			$('div.post:not(.' + year + ')').hide();
		} else {
			$("div.post, .year-filter-hide, .year-filter-heading").hide();
			$(".year-filter-hide").prev("br").hide();
			$(".year-filter-none").html("No projects in "+year).show();
		}
	
    });
	
	$(".show-older").click(function () { 
	
		$("a").removeClass("current-yr");
		var year = $(this).attr("title").toLowerCase();
		var display = $(this).attr("name");
		$(this).addClass("current-yr");
		
		if ($('div.post.'+year).length ) {
			$("div.post").show();
			$(".year-filter-none, .year-filter-hide").hide();
			$(".year-filter-hide").prev("br").hide();
			$(".year-filter-heading").html("Projects before "+display).show();
			$('div.post:not(.' + year + ')').hide();
		} else {
			$("div.post, .year-filter-hide, .year-filter-heading").hide();
			$(".year-filter-hide").prev("br").hide();
			$(".year-filter-none").html("No projects before "+display).show();
		}
	
    });
	
	$(".show-all").click(function () { 
		$("a").removeClass("current-yr");
		$(this).addClass("current-yr");
		$("div.post, .year-filter-hide").show();
		$(".year-filter-hide").prev("br").show();
		$(".year-filter-heading").html("Current Projects").show();
		$(".hidden").hide();
		$(".show").show();
    });
});